Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

html - I want to use javascript to insert an attribute to an element

Any ideas how I would go about writing a javascript method to insert an attribute to a tag

eg. I have

<input id='in1' value='Submit' type='submit'/>

and I want to insert an attribute name

<input id='in1' name='submit_content' value='Submit' type='submit'/>

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

document.getElementById("in1").setAttribute("name", "submit_content");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...