Javascript 通过jquery替换或预加值
我在变量var string中有一个字符串值,可以Javascript 通过jquery替换或预加值,javascript,jquery,Javascript,Jquery,我在变量var string中有一个字符串值,可以 var string = '$ <input id='text'>'; 如果在输入标记之前没有任何内容,是否有任何方法可以预先设置值,并限制在输入之前切断所有内容并预先设置要替换的字符串 要修复代码,请执行以下操作: function replaceValue(newVal) { amount.html(newVal + amount.html().slice(amount.html().indexOf('<input'
var string = '$ <input id='text'>';
如果在输入标记之前没有任何内容,是否有任何方法可以预先设置值,并限制
在输入之前切断所有内容并预先设置要替换的字符串
要修复代码,请执行以下操作:
function replaceValue(newVal) {
amount.html(newVal + amount.html().slice(amount.html().indexOf('<input')));
}
函数替换值(newVal){
amount.html(newVal+amount.html().slice(amount.html().indexOf(“切掉输入之前的所有内容,并在要替换的字符串前面加上前缀)
要修复代码,请执行以下操作:
function replaceValue(newVal) {
amount.html(newVal + amount.html().slice(amount.html().indexOf('<input')));
}
函数替换值(newVal){
amount.html(newVal+amount.html().slice(amount.html().indexOf(“为什么不在input
标记之前创建一个span
标记..然后使用js在其中设置值?不,我不能只将这些设置为单个标记,这是我的限制,抱歉在question@jitendrapurohit您也可以尝试这样的方法:谢谢,但我找到了@PaulBGDwhy不创建span
tag在input
tag之前。然后使用js在其中设置值?不,我不能只将这些设置为单个标记,这是我的限制,抱歉在question@jitendrapurohit你也可以尝试这样的方法:谢谢,但是我发现@Paulbgd建议的最好的方法是按预期工作。非常感谢!按预期工作非常感谢!
function replaceValue(newVal) {
amount.html(newVal + amount.html().slice(amount.html().indexOf('<input')));
}