2016-08-13 65 views
-1

是否有可能通过jQuery中的输入名称获取点击值?我没有班级和编号,我只想获得名称上的点击值。因为我正在用软件来完成所有这些工作以获取数据。是否有可能通过jQuery中的输入名称获取onclick值

<input type="button" name="view" value="Click To View Phone, Mobile &amp; Fax Numbers" onclick="viewphone(71241,'divid71241')"> 
+2

的可能的复制[我如何选择的名字与jQuery的元素?](http://stackoverflow.com/questions/ 1107220 /如何-可以-I-选择-AN-元件按姓名与 - jquery的) – Tibrogargan

回答

0

试试这个,这是很容易得到的onclick价值

<html> 
 
<head></head> 
 
<title></title> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
<body> 
 

 

 
<input type="button" name="view" value="Click To View Phone, Mobile &amp; Fax Numbers" onclick="viewphone(71241,'divid71241')" style="border: 0px;"> 
 

 
</body> 
 

 
<script type="text/javascript"> 
 
    
 
    $(document).ready(function(){ 
 
    \t $('[name=view]').click(function(){ 
 
    \t \t var valueis = $(this).attr('onclick'); 
 
    \t \t alert(valueis); 
 
    \t }); 
 
    }); 
 

 

 
</script> 
 

 
</html>

0

是使用下面的

onclick="viewphone(71241,'divid71241',this.value)" 
0

试试这一个。我相信你可以使用attr名称触发一个事件。

$('input[name=view]').click(function(){ 
    // functions here 
}); 
0

您可以使用attribute selector

例如,对于你的元素

<input type="button" name="view" value="Click To View Phone, Mobile &amp; Fax Numbers" onclick="viewphone(71241,'divid71241')" style="border: 0px;"> 

如果你只是有一个元素具有唯一名称:

$("input[name='view']").click(function() { 
// function data goes here 
console.log(this.value) 
}); 

如果你有多个同名的元素,你可以使用each() method

$("input[name='view']").each(function() { 
// function data goes here 
console.log(this.value) 
}); 

输出

Click To View Phone, Mobile & Fax Numbers 
// other input values here 

如果你有多个同名的元素,但只希望第一批价值您可以使用.first()方法:

$("input[name='view']").first(function() { 
// function data goes here 
console.log(this.value) 
}); 
相关问题