English 中文(简体)
j 质量——外地入口——如何复制和改成对流友好的尿素
原标题:jQuery - field entry - how to duplicate and convert to seo friendly url

我有两个超文本输入领域article url

页: 1 • 重复外地条款进入现场,向地轨道友好连接点:<>>

  • url allowed symbols a-z (capital letters converted to lowercase),
  • url space symbol replace with dash -,
  • url other symbols ignored.

仅在外地打字的要求

<input type="text" name="article">

<代码>url field is jquery auto produced and updated by field article 价值

<input type="text" name="url">
最佳回答

这一工作应当:

function name_to_url(name) {
    name = name.toLowerCase(); // lowercase
    name = name.replace(/^s+|s+$/g,   ); // remove leading and trailing whitespaces
    name = name.replace(/s+/g,  - ); // convert (continuous) whitespaces to one -
    name = name.replace(/[^a-z-]/g,   ); // remove everything that is not [a-z] or -
    return name;
}

之后

$( input[name=article] ).blur(function() {
    $( input[name=url] ).val(name_to_url($(this).val())); // set value
});

这在条款领域分散重点时,每当午餐场的价值就确定。


它保留了现有的<代码>-。 因此,如果你也想去除,那么,你必须修改<代码>的最后一行和第三行,即:

name = name.replace(/[^a-z ]/g,   ); // remove everything that is not [a-z] or whitespace
name = name.replace(/s+/g,  - ); // convert (continuous) whitespaces to one -

参考:http://api.jquery.com/blur/“rel=>nofollow noreferer”>.blur(,>>>,val()>,


<>Update:

我将设立一个新的职能,即:<代码>update_URL():

function update_URL() {
     var value = name_to_url($( input[name=article] ).val()) +  -  + $( input[name=year] ).val();
     $( input[name=url] ).val(value)
}

那么,你可以就任何事件,例如<代码>keyup():

$( input[name=article] ).keyup(function() {
    update_URL();
});
问题回答

暂无回答




相关问题
selected text in iframe

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.

How to fire event handlers on the link using javascript

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 ...

How to Add script codes before the </body> tag ASP.NET

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 ...

Clipboard access using Javascript - sans Flash?

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 ...

javascript debugging question

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 ...

Parsing date like twitter

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.

热门标签