English 中文(简体)
以xmlhttp.responseText为基础的变化风格
原标题:change css style based on xmlhttp.responseText

Ok here is my problem. I am trying to change the css style of a text field based on the responseText of an xmlhttpRequest using jQuery. If the company name is already taken the php file will echo "Company Name Already Taken." and I want the comp_stat box background to turn red. If the company name is unique the php file will echo "Company Name Ok" and I want the comp_stat box background to turn green.

这是“javascript”,所选案文是没有发挥作用的部分。

xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
        document.getElementById("comp_stat").value = xmlhttp.responseText;

        /*Not working part*/
        if(xmlhttp.responseText ==  Company Name Already Taken. ){
            document.getElementById("comp_stat").style.backgroundColor = "red";
        }
        if(xmlhttp.responseText ==  Company Name OK! ){
            document.getElementById("comp_stat").style.backgroundColor = "green";
        }
        /*----------------*/
}

我的头盔已满数小时,这或许是一个简单的固定点。 任何帮助都将受到高度赞赏。

问题回答

你强调的部分似乎没有问题。

However, maybe it is somewhere else in your code have error. I suggest you to use web inspectors or debuggers to debug. I really like Chrome s Developer Tools (it is really Apple s) it is really easy to use. It will show errors if there is any and you can also see the line number. enter image description here

它将显示错误之处。 非常有用。





相关问题
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.

热门标签