【发布时间】:2012-04-01 20:11:53
【问题描述】:
如果文本框处于焦点位置,我想禁用 jQuery 事件。我正在使用以下代码。如果用户在文本字段中输入任何文本,那么如果通过更改光标移动到图像,那么它将将文本字段中的文本重置为事件拍摄的值。如果文本字段处于焦点状态,我不想执行该事件。
<!DOCTYPE html>
<html>
<head>
<style>span {display:none;}</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<input type="text" id="team" />
<script>
$("input").focusin(function() {
document.getElementById("team").value = "I am in Focus Dont shoot events PLZ";
}
);
$(document).ready(function() {
$("img").mouseover(function(event) {
if(event.target.name != '')
{
document.getElementById("team").value = event.target.name;
}
//alert(event.target.name);
});
});
</script>
<img src="http://1.bp.blogspot.com/-bVD6mGlH_ik/TnHV75bw9KI/AAAAAAAAB84/1hJU7WJuU8k/s400/fewr.jpg" name="I" />
</body>
</html>
我已经尝试过以下功能
$("input").focusin(function() {
document.getElementById("team").value = "I am in Focus Dont shoot events PLZ";
});
现在我正在使用下面的代码,但仍然无法正常工作。请帮我。
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<img src="http://1.bp.blogspot.com/-bVD6mGlH_ik/TnHV75bw9KI/AAAAAAAAB84/1hJU7WJuU8k/s400/fewr.jpg" name="Ihhhhhhhhhhhhhhh" id="myimage" />
<input id="theone">
<input type="image" src="http://www.clker.com/cliparts/e/2/a/d/1206574733930851359Ryan_Taylor_Green_Tick.svg.thumb.png" id="bind">
<input type="image" src="http://www.clker.com/cliparts/4/3/1/f/1195436930767206781not_ok_mark_h_kon_l_vdal_01.svg.thumb.png" id="unbind">
<script>
$("#unbind").click(function(event) {
$("img").off();
alert("off");
});
$("#bind").click(function(event) {
$("img").on();
alert("on");
});
$("img").mouseover(function(event) {
if(event.target.name != '')
{
document.getElementById("theone").value = "done";
}
//alert(event.target.name);
});
</script>
</body>
</html>
【问题讨论】:
-
具体说明您的要求。不明白你想要什么..
-
图片名称的页面加载值输入文本框后。但是当该文本框处于焦点时,我想禁用这个东西。并且在焦点从文本字段中出来后也会反应这个东西。希望你理解PLZ的帮助
-
是的..得到你的要求...检查我在评论中发布的答案..
标签: java jquery ajax jquery-selectors jquery-events