Display only 10 characters of a long string?
问题 How do I get a long text string (like a querystring) to display a maximum of 10 characters, using JQuery? Sorry guys I'm a novice at JavaScript & JQuery :S Any help would be greatly appreciated. 回答1: If I understand correctly you want to limit a string to 10 characters? var str = 'Some very long string'; if(str.length > 10) str = str.substring(0,10); Something like that? 回答2: And here's a jQuery example: HTML text field: <input type="text" id="myTextfield" /> jQuery code to limit its size: