开发者

jQuery in Ubuntu not working, but on windows its fine

开发者 https://www.devze.com 2023-02-25 11:56 出处:网络
I have this simple jQuery code $(document).ready(function() { $(\'#test\').attr(\'value\',\'hello world\');

I have this simple jQuery code

$(document).ready(function() {
    $('#test').attr('value','hello world');
    $('#test1').text('hello world');
    });

And the div / textbox

<input type="text" id="test" value="">
<div id="test1" style="width:100px; height:100px;">xxx</div>

Any reasons to why it is not working fine. There are no javascript errors too.

[update-1] Making his more easier, jquery does not work on ubuntu a开发者_Python百科t all

[update-2] html inline

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title> 
<script language="javascript" src="jquery-1.5.min.js"  type="text/javascript"></script> 

<script type="type/javascript"> 

$(document).ready(function() {
    $('#test').attr('val','hello world');
    $('#test1').text('hello world');
    });

</script> 

</head>

<body> 
<input type="text" id="test" value="">
<div id="test1" style="width:100px; height:100px;">xxx</div>

</body>
</html>

Thanks Jean


Tried this under Ubuntu 10.04, and Firefox 3.6.12, and it works fine:

<html>
<head>

<script language="javascript" type="text/javascript" src="jquery-1.5.2.min.js"></script>
<script language="javascript" type="text/javascript">

$(document).ready(function() {
    $('#test').attr('value','hello world');
    $('#test1').text('hello world');
    });

</script>
</head>

<body>


<input type="text" id="test" value="">
<div id="test1" style="width:100px; height:100px;">xxx</div>

</body>

</html>

Notice I changed $('#test').attr('val','hello world'); to $('#test').attr('value','hello world');

I hope that helps.


I agree with others that the problem is the browser (or, possibly, the setup of the browser), and not Ubuntu itself. You should check global settings (of the browser) and start narrowing down the problem. This is particularly true if even the simplest jQuery isn't working.

  1. First thing first - make sure JavaScript works. Is it enabled in the Chrome installation on your Ubuntu machine?
  2. Is it only your own site that you are having problems? If you try to visit Stackoverflow on your Ubuntu machine, for example, does the JavaScript work properly there?
  3. If it is only your website, is the website being run from a server local to the machine? If so, is it a permissions problem? Are you sure you're actually retrieving the jQuery library? One way to test this is to use the Google CDN libraries. Chrome's developer tools (Ctrl + Shift + I) can provide more detail as to what is and is not being retrieved.

Basically when you have a problem like this (particularly if everybody is telling you that your code works), you need to start narrowing down the scope of the problem. Start with the obvious and work your way down from there.

0

精彩评论

暂无评论...
验证码 换一张
取 消