2016-11-11 133 views
-3

在这里,我想陷阱和警报或echo var值thisCount 问题是我无法显示value.I'd试了很多办法,但没有运气。如何在javascript中显示变量的值?

$(document).on("click", ".open-dialog", function() { 

    var thisCount = $(this).data('count'); 

    //this place the code 

    $(".modal-body #count").val(thisCount); 
}); 
+3

您需要提供一个[MCVE],并学习如何使用代码格式化编辑#1的功能。 – Quentin

+0

你可以使用'.html()' –

+0

'alert(value)'? – jdmdevdotnet

回答

1

你的问题并没有真正阐明你已经尝试什么,或者你想要显示的值,但常见的答案是:

1)控制台。这将输出到您的浏览器日志。

console.log(thisCount); 

2)如果你希望把它变成一个HTML标记,你可以使用经典的JavaScript

document.getElementById('yourTagsId').innerHTML += thisCount; 
// You can use = instead of += as well 

3)您也可以使用提醒或确认

alert(thisCount); 

confirm(thisCount, function(){return true;}); 
// confirm takes both a displayed value, and a function which will be performed when the user presses the 'Ok' button 
0

也许你应该验证是否jQuery库正确导入 此外,您还可以使用Chrome开发人员工具(按Ctrl +移位 + ),并验证在JavaScript控制台的值。只是为了看看你是否可以在调试器中看到这个值。

0

如果您需要啊data属性这样的下面。 alertconsole.log都正在

$(document).on("click", ".open-dialog", function() { 
 

 
    var thisCount = $(this).data('count'); 
 

 
    $("#count").val(thisCount); 
 
    console.log(thisCount) 
 
    alert(thisCount) 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<button class="open-dialog" data-count="hello">click</button> 
 
<input type="text" id="count">