<a onclick ="foo()" href="bar.html" >Link </a>
<script>
...
function foo(){
//I want to know the href property of whoever called me.
//something like this.caller.href ??
}
</script>
Run Code Online (Sandbox Code Playgroud)
我想我可以只分配所有元素ID,然后将我自己的ID传递给我正在调用的JS方法,但我一直在寻找更好的方法.
我需要捕获keyup事件以在用户输入输入时提供实时验证(仅当输入失去焦点时才会触发更改事件).
我无法获取触发evnt的输入的编辑值.
该代码还在定时器上运行,以防止在用户键入时多次调用(每500毫秒触发一次).
我有几个输入类"priceinput"并附加到每个的keyup事件,如下所示:
<script language="javascript" type="text/javascript">
var timer;
$(document).ready(function()
{
$(".priceinput").each(function()
{
$(this).keyup(function(e)
{
clearTimeout(timer);
timer = setTimeout(function()
{
//how to get the value of the input element that was changed?
var value = ???;
$.getJSON('/Validator/IsValidInput', { input: value },
function(response)
{
//indicate if input is correct
});
}, 500);
});
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
为了让发件人输入值,我都试过$(this).val,this.val(),e.target.val()但没有似乎工作.
如何获取发件人输入的值?