鉴于代码行
var value = $("#text").val();
www.un.org/spanish/ga/president 我如何利用 Java来取代本文的功能?
鉴于代码行
var value = $("#text").val();
www.un.org/spanish/ga/president 我如何利用 Java来取代本文的功能?
希望:
var value = $("#text").val(); // value = 9.61 use $("#text").text() if you are not on select box...
value = value.replace(".", ":"); // value = 9:61
// can then use it as
$("#anothertext").val(value);
更新,以反映目前版本的j Query。 这里还有许多答案最适合这种情况。 作为发展者,你们需要知道什么。
替换多种特性时使用某些东西:.replace(/&/g,“-”
。 在此,我替换了所有<代码>&。 <代码>->>。
<>说明>——您可能需要添加方括号,以避免出现错误——<代码>,replace(/[+]/g,“
Dante Cullari
或许,这样做的最可取方式就是采取一个步骤。 见val(
。
$("#text").val(function(i, val) {
return val.replace( . , : );
});
相比之下:
var val = $("#text").val();
$("#text").val(val.replace( . , : ));
参考:
.val( function(index, value) )
function(index, value)A function returning the value to set.
This method is typically used to set the values of form fields. For
<select multiple="multiple">
elements, multiple s can be selected by passing in an array.The
.val()
method allows us to set the value by passing in a function. As of jQuery 1.4, the function is passed two arguments, the current element s index and its current value:$( input:text.items ).val(function(index, value) { return value + + this.className; });
This example appends the string " items" to the text inputs values.
这就需要j Query 1.4+。
var value = $("#text").val().replace( . , : );
//Or if you want to return the value:
return $("#text").val().replace( . , : );
简单一行:
$("#text").val( $("#text").val().replace(".", ":") );
可以通过定期的 Java印功能replace(<>/code>进行。
value.replace(".", ":");
您可使用 Java文功能,如取代,并可在括号中总结 j法:
var value = ($("#text").val()).replace(".", ":");
$("#text").val(function(i,v) {
return v.replace(".", ":");
});
(9.61 + "").replace( . , : )
或者,如果贵国的<代码>9.61已经作了说明:
"9.61".replace( . , : )
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.