jquery and html
hi can anyone tell me how a text field is generated when a button is clicked and that button is on jquery side. I have done the 开发者_高级运维following :
$("#addButton").click(function()
$(this).before('<input type="textbox" name="textbox' + tempCounter + '" id="textbox' +
tempCounter + '" value="no use" /><br/>');
In this way whenever a button with id "addButton" is clicked , a text field is generated but the problem is this text field is generated on jquery side and i want it to be a part of htmllike whenever the same button is clicked a new text field is autogenerated inside the html page. I had tried it using for loop but stuck ... can anyone suggest?
You could add it upp like this:
$(this).before($(this).before + [Your HTML CODE]);
But be aware, it will never really exist in the HTML code.
So what you are asking is to have the button added to the HTML? It does this with the above code, but it won't add it to the file and then save that file. The JavaScript is only manipulating the DOM. Once you refresh those elements wouldn't exist any longer.
Is there a specific issue with the above code that isn't working for you?
精彩评论