I would like to combine
开发者_JAVA技巧$("#myId").val()
and
$(this).val()
so that I can use the same id and a name value connected to an array -- characters[x].name
-- to store and display different names.
http://jsfiddle.net/ren1999/Fae95/
Assuming the layout of input elements is somewhat similar, you could just find the sibling of the input box, and assign the text to it.
$("#getName1, #getName2").blur(function() {
var name = $(this).val();
$(this).siblings('b').text(name);
}).blur();
http://jsfiddle.net/Fae95/1/
Try this:
$.each([["#getName1", "#displayName1"], ["#getName2", "#displayName2"]],
function (i, names) {
$(names[0]).blur(function () {
var name=$(this).val();
$(names[1]).text(name);
});
})
You can simply add more inputs by adding them too the array.
Here is the solution to my problem. I am able to make a field appear, enter a new value, click the field again and make the field disappear with the new value. The Firefox error console complains every time that this.refresh() is not a function, but I don't care as it works.
var gotIt='no'
function askName(x)
{if(gotIt=='yes')
{response=this.name
characters[x].setName(response)
gotIt=0
}
else
{gotIt='no'
this.name=characters[x].name
response="<input onClick=_setName(this.value) size=10 type=text value="+this.name+">"
characters[x].setName(response)
}
}
function _setName(x)
{this.name=x
this.refresh()
gotIt='yes'
}
精彩评论