Is it possible to get on click value by input name in jQuery? I don't have neither class nor id and I want to get the on click value on name only. As I am doing all this in a software to get data.
<input type="button" name="view" value="Click To View Phone, Mobile & Fax Numbers" onclick="viewphone(71241,'divid71241')">
Is it possible to get on click value by input name in jQuery? I don't have neither class nor id and I want to get the on click value on name only. As I am doing all this in a software to get data.
<input type="button" name="view" value="Click To View Phone, Mobile & Fax Numbers" onclick="viewphone(71241,'divid71241')">
Share
Improve this question
edited Aug 13, 2016 at 16:36
halfer
20.4k19 gold badges109 silver badges202 bronze badges
asked Aug 13, 2016 at 7:13
Hitesh ChauhanHitesh Chauhan
872 gold badges4 silver badges13 bronze badges
1
- 2 Possible duplicate of How can I select an element by name with jQuery? – Tibrogargan Commented Aug 13, 2016 at 7:16
5 Answers
Reset to default 2try this , it is easy to get onclick value
<html>
<head></head>
<title></title>
<script src="https://ajax.googleapis./ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<body>
<input type="button" name="view" value="Click To View Phone, Mobile & Fax Numbers" onclick="viewphone(71241,'divid71241')" style="border: 0px;">
</body>
<script type="text/javascript">
$(document).ready(function(){
$('[name=view]').click(function(){
var valueis = $(this).attr('onclick');
alert(valueis);
});
});
</script>
</html>
You could use the attribute selector
For example for your element
<input type="button" name="view" value="Click To View Phone, Mobile & Fax Numbers" onclick="viewphone(71241,'divid71241')" style="border: 0px;">
If you just have one element with a unique name:
$("input[name='view']").click(function() {
// function data goes here
console.log( this.value )
});
If you have multiple elements with the same name you can use the each() method
$("input[name='view']").each(function() {
// function data goes here
console.log( this.value )
});
Output
Click To View Phone, Mobile & Fax Numbers
// other input values here
If you have multiple elements with the same name but only want the first ones value you can use the .first()
method:
$("input[name='view']").first(function() {
// function data goes here
console.log( this.value )
});
yes use the following
onclick="viewphone(71241,'divid71241',this.value)"
Try this one. I believe you can use attr name to trigger an event.
$('input[name=view]').click(function(){
// functions here
});
Yes , you can do that by using [attribute] selector .
input[name="view"]
will select that particular Element.
$('input[name="view"]').click(function(){
});
Here is a reference link : https://api.jquery./attribute-equals-selector/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744140861a4560199.html
评论列表(0条)