Edit The Code:
See Result »
Try it Yourself - ©
w3big.com
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>本教程(w3big.com)</title> <script src="http://cdn.static.w3big.com/libs/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("input[name~='nation']").css("background-color","yellow");}); </script> </head> <body> <input name ="nationality" type="text" value="Chinese"> <input name="nation" type="text" value="English"> <input name="country" type="text" value="Germany"> <input name="anothernation" type="text" value="Norwegian"> <p>选取所有 name 属性包含 'nation' 单词的 input 元素。</p> <p><b>注意</b>: 选取的是'nation' 单词,而不是以 "nation" 开头或结束的单词(例如 "nationality" 和 "anothernation")。 </body> </html>