2016-08-13 46 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) 
}); 
相關問題