Javascript 使用按钮onclick时不显示警报
这是小提琴 我正在尝试这样做,当您单击按钮时,它会提示“您试图搜索…”…无论您键入了什么…Javascript 使用按钮onclick时不显示警报,javascript,jquery,jquery-ui,alert,Javascript,Jquery,Jquery Ui,Alert,这是小提琴 我正在尝试这样做,当您单击按钮时,它会提示“您试图搜索…”…无论您键入了什么…!”,但该按钮不会提示消息 我已经尝试使用: var a = document.getElementById('input').value; alert("You tried to search " + a + "!"); 而且它仍然没有提醒消息,请回答?您的功能在关闭之外无法访问。应该是 window.search = function() { var a = document.getE
!”代码>,但该按钮不会提示消息
我已经尝试使用:
var a = document.getElementById('input').value;
alert("You tried to search " + a + "!");
而且它仍然没有提醒消息,请回答?您的功能在关闭之外无法访问。应该是
window.search = function() {
var a = document.getElementById('input').value;
alert("You tried to search " + a + "!");
}
您的函数在其闭包之外无法访问。应该是
window.search = function() {
var a = document.getElementById('input').value;
alert("You tried to search " + a + "!");
}
您的代码将在加载此页面后立即运行,您可以像这样优化代码[使用jquery]:
$(document).ready(function(){
$('#search').onclick(function() {
var a = document.getElementById('input').value;
alert("You tried to search " + a + "!");
});
});
您的代码将在加载此页面后立即运行,您可以像这样优化代码[使用jquery]:
$(document).ready(function(){
$('#search').onclick(function() {
var a = document.getElementById('input').value;
alert("You tried to search " + a + "!");
});
});
如果您使用jQuery,那么应该使用jQuery绑定click事件,这样会更好
删除onclick
<button id="clickme" type="button" title="Search" value="Search">Search</button>
如果您想访问search()
where
// create jQuery plugin function
$.search = function (s) {
alert(s);
}
// now you can call search like this
$.search('search string');
如果您使用jQuery,那么应该使用jQuery绑定click事件,这样会更好
删除onclick
<button id="clickme" type="button" title="Search" value="Search">Search</button>
如果您想访问search()
where
// create jQuery plugin function
$.search = function (s) {
alert(s);
}
// now you can call search like this
$.search('search string');