Monday 15 April 2013

javascript - Setting the Input Value attribute to a variable with space. -


I am trying to set the value of an input button in a string variable.ie "A guide to school bus" I am But when the HTML loads, only the first word comes in the button. My code is given below thanks for the help.

  var title = "A guide to school bus"; Var html string = "& lt; div class =" + title + "& gt;" + "& Lt; input type =" + "button" + "value =" + title + "onclic = loadbook ()>" + "& lt; / div & gt;"; $ (HtmlString) .appendTo (attachPoint);   

And the attachment is a reference in HTML which I am using the following.

  var attachpoint = document.query selector ('. Button at pointpoint');    

The problem is because you are not quitting around the attribute values, try it:

  var htmlString = '& lt; Div class = "'+ + +" "" gt; & lt; input type = "button" value = "' + + title" + "onclic =" loadbook () "& gt; & Lt; / Div & gt; ';   

You can either avoid " in your string, just like I did, just between ' and Switch ". " will be displayed as a normal character and ' is used to mark the beginning and end of the strings.

One As a side point, you probably want to put the t on title to class on div , because it is a different , So in your example, 6 sections will be added to the div.

No comments:

Post a Comment