2014-04-01 15 views
1

我想将jquery函数结果显示到引导模型主体。想要将jquery函数结果显示到引导模型主体

jQuery的功能

function randomNumberRange(min, max) 
{ 
    var x= Math.floor(Math.random() * (max - min + 1) + min); 
    console.log(x); 

    return Math.floor(Math.random() * (max - min + 1) + min); 
} 
在.html文件模特身上

<div class="modal-body"> 

      </div> 

我想x的值应该得到在模特身上显示HTML。

有一个提交按钮启动模型

<button onclick="location.href = '/poll/result/';" id="myButton" class="float-left submit-button" >submit</button> 
</div> 

所以一旦我在提交应显示X在模特身上的价值点击。 请帮我一把。

+0

看看这个答案 - http://stackoverflow.com/questions/14971766/load-content-with-ajax- in-bootstrap-modal – Nick

+0

我不使用ajax这个....... – Wagh

回答

1

HTML:

<button id="myButton">submit</button> 
    <div id="modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 
     <div class="modal-body"> 

     </div> 
    </div> 
    </div> 
</div> 

JS:

function randomNumberRange(min, max) 
{ 
    var x= Math.floor(Math.random() * (max - min + 1) + min); 
    console.log(x); 

    return Math.floor(Math.random() * (max - min + 1) + min); 
} 

$(document).ready(function() { 
    $('#modal').modal({show:false}); 

    $('#myButton').click(function(e) { 
    $('.modal-body').text(randomNumberRange(1,2)); 
    $('#modal').modal('show'); 
    }); 

}) 

EXAMPLE

+0

干草谢谢我得到了你的答案,但仍然没有得到结果。我需要把这个代码放在randomNumberRange()函数或其他地方。 – Wagh

+0

里面 '$(文件)。就绪()' – Nick

+0

$(文件)。就绪(函数(){ \t $( '#为myButton')点击(函数(E){ e.preventDefault(); $ ('.modal-body').text(randomNumberRange(60,100)); $('#mymodal').model('show'); }); });它不工作。 – Wagh