Bug Tracker

Ticket #4299: jQueryBug.2.html

File jQueryBug.2.html, 2.2 KB (added by soswow, 11 years ago)

Same example with success native DOM working.

Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
6        <title>jQuery bug</title>
7       
8<script type="text/javascript">
9$(function(){ 
10  doChanges("form1");
11  doChanges("form2");
12});
13
14function log(msg){
15  $("#logger").append(msg + "<br/>"); 
16}
17
18function doChanges(formid){
19  log("+++++++++++++++++");
20  log("Working with formid = "+formid);
21  var $form = $("#"+formid);
22 
23  testFieldChanging($form, "action", "#newAction");
24  log(" ");
25  testFieldChanging($form, "method", "post");
26}
27
28function testFieldChanging($form, fieldName, newAttr){
29  log("Start "+fieldName+" attr = " + $form.attr(fieldName));
30  log("Changing "+fieldName+" attr to "+newAttr);
31 
32  $form.attr(fieldName, newAttr);
33 
34  log("Now "+fieldName+" attr = "+ $form.attr(fieldName));
35  var actionResult = ($form.attr(fieldName).toLowerCase() === newAttr.toLowerCase() )?"<span style='color:green;'>CHANGED</span>":"<span style='color:red;'>NOT CHANGED</span>";
36  log("Result: "+fieldName+" attr is "+actionResult);
37 
38  log("Try with classic DOM");
39  changeAction($form.attr("id"), fieldName, newAttr);
40  log("Now "+fieldName+" attr = "+ $form.attr(fieldName));
41  var actionResult = ($form.attr(fieldName).toLowerCase() === newAttr.toLowerCase() )?"<span style='color:green;'>CHANGED</span>":"<span style='color:red;'>NOT CHANGED</span>";
42  log("Result: "+fieldName+" attr is "+actionResult);
43}
44
45function changeAction(formId, attribute, newValue){
46        $("#"+formId)[0].attributes[attribute].value = newValue; 
47}
48
49</script>
50
51</head>
52<body>
53
54<form id="form1" action="#action1" method="get">
55  <!-- Nothing here -->
56</form>
57
58<form id="form2" action="#action2" method="get">
59  <!-- Nothing here -->
60  <input type="text" name="action" value="Action Start Value" />
61  <input type="text" name="method" value="Method start Value" />
62</form>
63
64
65<div id="logger">
66
67</div>
68</body>
69</html>