替换搜索表单字符串中的值

时间:2014-01-04 19:45:36

标签: javascript string

我想要一些帮助,我已经搜索过,但似乎没有任何效果。

我有以下代码用于网站搜索功能。我的问题是因为存储值的所有值都是小写而没有语调,我希望输入关键字(search_text)失去语调(希腊语)。我已设法将其设为小写,如下所示:

document.getElementById("txt_search").value = document.getElementById("txt_search").value.toLowerCase();

但是,我不习惯去除语调!

基本上我需要一些代码不仅可以降低输入的大小,还可以删除语调。

以下是代码:

function ajaxPagingCall(page, queryString, fileName){

/*
$.get(site_url + "/modules/search/"+queryString+"&page="+page, function(data) {
  $('#isShowLiveSearch').html(data);
});
*/
document.getElementById("txt_search").value = document.getElementById("txt_search").value.toLowerCase();
var search_txt = document.getElementById("txt_search").value;

var frmPrice=$('#price-Slider').val().split(';');
var frmFirstPrice   = frmPrice[0];

var frmSecondPrice  = frmPrice[1];
var frmDisc=$('#discount-Slider').val().split(';');
var frmFistDisc     = frmDisc[0];
var frmSecondDisc   = frmDisc[1];

var price_start=(frmFirstPrice)?frmFirstPrice:0;
var price_end=(frmSecondPrice)?frmSecondPrice:0;
var discount_start=(frmFistDisc)?frmFistDisc:0;
var discount_end=(frmSecondDisc)?frmSecondDisc:0;


var elemt=document.getElementsByName("chkcategory[]");

var webelemt=document.getElementsByName("website[]") ;
//alert(webelemt);

var arr=new Array();
var j=0;

for(var i=0; i<elemt.length;i++)
{
    if(elemt[i].checked==true){
        arr[j]=elemt[i].value;
        j++;
    }
}

var catids=arr.join(",");


var arr1=new Array();
    var b=0;
    for(var a=0; a<webelemt.length;a++){
        if(webelemt[a].checked==true){
            arr1[b]=webelemt[a].value;
            b++;
        }
    }

    var webids=arr1.join(",");

/********** Loading Script **********/
displayLoaderIn("replacediv");
/********** Enf of Loading Script **********/

$.ajax({
  url: site_url+"ajax_search_deals.php",      
  type: "POST",
  data: "webids="+webids+"&catids="+catids+"&search_txt="+search_txt+"&page="+page+"&startPrice="+price_start+"&endPrice="+price_end+"&startDisc="+discount_start+"&endDisc="+discount_end+"&show_filters="+show_filters+"&set_order_date="+set_order_date+"&set_order_price="+set_order_price+"&set_order_discount="+set_order_discount,
  success: function(responce_msg){
    $("#replacediv").html(responce_msg);
  }
 }) 
}

2 个答案:

答案 0 :(得分:0)

这是一个功能,它将为您完成:

function removeAccents(strAccents) {
        var strAccents = strAccents.split('');
        var strAccentsOut = new Array();
        var strAccentsLen = strAccents.length;
        var accents = 'αβγδεζηθικλμ';
        var accentsOut = 'ΑΒΓΔΕΖΗΘΙΚΛΜ';
        for (var y = 0; y < strAccentsLen; y++) {
            if (accents.indexOf(strAccents[y]) != -1) {
                strAccentsOut[y] = accentsOut.substr(accents.indexOf(strAccents[y]), 1);
            } else
                strAccentsOut[y] = strAccents[y];
        }
        strAccentsOut = strAccentsOut.join('');
        return strAccentsOut;
    }

所以你可以执行var a = document.getElementById("txt_search").value; a.value = removeAccents(a.value);

很难找到希腊方言,所以我最终使用了http://en.wikipedia.org/wiki/Greek_alphabet

请注意,它是古希腊,我不知道你想要什么。无论如何,你应该能够自己编辑它。

答案 1 :(得分:0)

我尝试了你的答案但是没有用。最后我用它做了。如果将来有人需要它!谢谢大家的帮助!

document.getElementById("txt_search").value = document.getElementById("txt_search").value.toLowerCase();
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("ά", "α");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("Ά", "α");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("έ", "ε");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("Έ", "ε");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("ή", "η");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("Ή", "η");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("ί", "ι");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("Ί", "ι");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("ό", "ο");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("Ό", "ο");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("ύ", "υ");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("Ύ", "υ");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("ώ", "ω");
document.getElementById("txt_search").value = document.getElementById("txt_search").value.replace("Ώ", "ω");
var search_txt = document.getElementById("txt_search").value;