如何从有两个文本框的jQuery对话框中获取值?我可以将它们存储在JavaScript变量中吗

How can I get values from jQuery dialog box which has 2 text boxes? Can I store them in a JavaScript variable?

本文关键字:我可以 获取 变量 JavaScript 存储 对话框 jQuery 文本 两个      更新时间:2023-09-26

我尝试过jQuery,但无法从该对话框中获取值。有没有任何方法可以将这些值存储在JavaScript变量中(即,来自jQuery对话框)。

<div id="dialog-message2">
  <center><p>
    What percentage would you like to refund?</br>
    <input type="text" id="per" name="per" > %
    </p></center>
    <center><p>
    Reason: <input type="text" id="reason" name="reason" >
    </p></center>

    <br><center><input type="submit" id="proceed" name="proceed" value="PROCEED" style='width:60px;height:30px;background-color:#0066CC;color:#FFFAF0; -webkit-border-radius: 9px'></center>
</div>

或者JavaScript中还有其他方法吗?

$(document).ready(function(){
    $("#proceed").click(function(){
    //using JQuery
    var perValue = $("#per").val();
    var reasonValue = $("#reason").val();
    console.log(reasonValue);
    console.log(perValue);
    });    
});
//using javascript
document.getElementById('proceed').onclick = Onclick;
function Onclick(){
    var reasonValue = document.getElementById("reason").value;    
    var perValue = document.getElementById("per").value;
    console.log(reasonValue);
    console.log(perValue);
}

我已经包含了Jquery和基于按钮的onlick函数的普通javascript。你可以在JsFiddle上测试一下。您可以检查控制台以查看var值的输出。

这就是您想要的吗?

var something = document.getElementById("yourIDhere").value;
相关文章: