在本地运行Javascript而不是连接到JQuery

时间:2013-04-25 09:16:52

标签: jquery local

是否可以从我的网站本地运行脚本而不是将其连接到Jquery.com托管的库/查询? 目前,它在线连接到另一个页面以执行查询,但是所有功能都在代码中,我需要它在本地运行,而不需要在线librbary或后台的任何库

由于

代码:

<script type="text/javascript" src="http://www.freshessays.com/jquery.min.js"></script>!-- Start Calculator block --

table class="fe_calc fe_block_templ"
<tr>
    <td>Academic level:</td>
    <td>
        <select id="calform_academic_level1" name="academic_level" onchange="calcountPrice1();" style="width:140px;">
            <option value="0">Please select</option>
            <option value="1">High School</option>
            <option value="2">Bachelor</option>
            <option value="3">Master</option>
            <option value="4">PhD</option>
            <option value="5">Admissions Help</option>
        </select>
        <em class="validator_exp"></em>
    </td>
</tr>
<tr>
    <td>Deadline:</td>
    <td>
        <select id="calform_deadline1" name="deadline" onchange="calcountPrice1();" style="width:140px;">
            <option value="0" selected="selected">Please select</option>

            <option value="1">24 hours</option>

            <option value="2">48 hours</option>

            <option value="3">3 days</option>

            <option value="4">4 days</option>

            <option value="5">5 days</option>
            <option value="6">6 days</option>
            <option value="7">7 days</option>

            <option value="8">8 days</option>
            <option value="9">9 days</option>
            <option value="10">10 days</option>
            <option value="11">11 days</option>

            <option value="12">12 days</option>
            <option value="13">13 days</option>
            <option value="14">14+ days</option>
        </select>

        <em class="validator_exp"></em>
    </td>
</tr>

<tr>
    <td id="pages_name1">Number of pages:</td>
    <td>

        <input maxlength="3" style="width: 40px;" id="calform_pages1" name="pages" 
onkeyup="calcountPrice1();" onkeydown="calcountPrice1();" onchange="calcountPrice1();" type="text">
        <em class="validator_exp"> </em>
    </td>
</tr>
<tr>
    <td>The price is:</td>
    <td>
        <span id="calprice_div1">AED 0</span>
    </td>
</tr>
<tr>
    <td></td>

</tr>
</table>

var calvalid;

function calvalidate_field (field_id) {
var value = $("#"+field_id).val();
var tmp_reg_exp = $("#"+field_id).next(".validator_exp").html();
reg_exp = new RegExp(tmp_reg_exp);
if (!value.match(reg_exp) || (field_id == "form_repeat_password" && !check_password("form_new_user_password","form_repeat_password"))) {
    calvalid = false;
    return false;
}
return true;
}


var caldeadline = new Array
(new Array ( 0,135,153,188,235,318),
new Array ( 0,124,141,170,206,288),
new Array ( 0,106,129,153,177,235), new Array ( 0,106,129,153,177,235), new Array ( 0,106,129,153,177,235), new Array ( 0,106,129,153,177,235),
new Array ( 0,94,118,141,165,218), new Array ( 0,94,118,141,165,218),new Array ( 0,94,118,141,165,218),new Array ( 0,94,118,141,165,218),
new Array ( 0,94,118,141,165,218), new Array ( 0,94,118,141,165,218),new Array ( 0,94,118,141,165,218),
new Array ( 0,82,106,129,153,200));

$(document).ready(function() {
$(".right_email").attr("href","mai"+"lto:su"+"ppor"+"t@fres"+"hessays.c"+"om").text("su"+"ppor"+"t@fres"+"hessays.c"+"om");
$("#calform_deadline").val(0);
$("#calform_academic_level").val(0);
});

function calcountPrice() {
calvalid = true;

calvalidate_field("calform_academic_level");

if (calvalid) {
    var al = $("#calform_academic_level").val();
}


var add = 1;
var round_off = false;
var pages_name = 1;     


if (pages_name == 1) {            
    $("#pages_name").text("Number of pages:");    
}

calvalidate_field("calform_deadline");

if (!calvalid) {
    $("#calprice_div").text("AED 0");            
} else {

    var total = caldeadline[$("#calform_deadline").val()-1][al];
    var price_mod = 0.85;
    var work = 1;
    total = Math.round(Math.round(total*price_mod*add*(round_off? 10 : 1))*work)/(round_off? 10 : 1);            
}

var valid1 = calvalid;
calvalid = true;
calvalidate_field("calform_pages");

if (!calvalid) {
    $("#calprice_div").text("AED 0");            
}

if (calvalid && valid1) {
    totalp = total*$("#calform_pages").val();
    $("#calprice_div").text("AED "+Math.round(totalp*100)/100);            
}

}

function calcountPrice1() {
calvalid = true;

calvalidate_field("calform_academic_level1");

if (calvalid) {
    var al = $("#calform_academic_level1").val();
}


var add = 1;
var round_off = false;
var pages_name = 1;         

if (pages_name == 1) {            
    $("#pages_name1").text("Number of pages:");    
}
calvalidate_field("calform_deadline1");

if (!calvalid) {
    $("#calprice_div1").text("AED 0");            
} else {

    var total = caldeadline[$("#calform_deadline1").val()-1][al];
    var price_mod = 0.85;
    var work = 1;
    total = Math.round(Math.round(total*price_mod*add*(round_off? 10 : 1))*work)/(round_off? 10 : 1);            
}

var valid1 = calvalid;
calvalid = true;
calvalidate_field("calform_pages1");

if (!calvalid) {
    $("#calprice_div1").text("AED 0");            
}

if (calvalid && valid1) {
    totalp = total*$("#calform_pages1").val();
    $("#calprice_div1").text("AED "+Math.round(totalp*100)/100);            
}

}

</script>

3 个答案:

答案 0 :(得分:1)

您可以从here下载脚本文件并将其存储在本地计算机上。然后在HTML页面中使用<script src="path/to/jquery.min.js" type="text/javascript></script>来获取jQuery。

答案 1 :(得分:0)

您想要实现的目标很有可能,但您必须将jQuery选择器和方法更改为javascript版本的选择器和方法,如:

如果您有$('#selector')表示选择id,那么您可以做的是:

改变这个:

$('#selector')

到此:

document.getElementById('selector')

同样适用于以下方法:

.val()

.value

所以改变这个:

 $('#selector').val()

到此:

document.getElementById('selector').value;

您可以将jQuery的.text()更改为javascript的.innerHTML

和当前$(document).ready(function() {....});必须更改为javascript的window.onload=function(){...};

答案 2 :(得分:0)

在本地下载和使用jQuery,或者只使用普通的JS

在我做了一些更改之后,这是脚本的DEMO。它不起作用,因为HTML不包含所需的所有东西,如正则表达式

var calvalid;

function calvalidate_field (field_id) {
  var fld = document.getElementById(field_id);
  var value = fld.value;
  var tmp_reg_exp = fld.parentNode.getElementsByClassName("validator_exp")[0].innerHTML;
  reg_exp = new RegExp(tmp_reg_exp);
  if (!value.match(reg_exp) || (field_id == "form_repeat_password" && !check_password("form_new_user_password","form_repeat_password"))) {
    calvalid = false;
    return false;
  }
  return true;
}


var caldeadline = [
  [0,135,153,188,235,318],[0,124,141,170,206,288],[0,106,129,153,177,235], 
  [0,106,129,153,177,235],[0,106,129,153,177,235], [0,106,129,153,177,235],
  [0,94,118,141,165,218],[0,94,118,141,165,218],[0,94,118,141,165,218],
  [0,94,118,141,165,218],[0,94,118,141,165,218],[0,94,118,141,165,218],
  [0,94,118,141,165,218],[0,82,106,129,153,200]
];

window.onload=function() {
  // you need to change the email from class to ID:
  var email = document.getElementById("right_email");
  email.setAttribute("href","mai"+"lto:su"+"ppor"+"t@fres"+"hessays.c"+"om");
  email.innerHTML="su"+"ppor"+"t@fres"+"hessays.c"+"om";

  // I added <a href="#" id="right_email"></a>
  document.getElementById("calform_deadline1").value=0;
  document.getElementById("calform_academic_level1").value=0;
};

function calcountPrice() {
  calvalid = true;
  calvalidate_field("calform_academic_level");
  if (calvalid) {
    var al = document.getElementById("calform_academic_level").value;
  }

  var add = 1;
  var round_off = false;
  var pages_name = 1;     
  if (pages_name == 1) {
    document.getElementById("pages_name").innerHTML="Number of pages:";    
  }

  calvalidate_field("calform_deadline");
  if (!calvalid) {
    document.getElementById("calprice_div").innerHTML="AED 0";
  } else {
    var total = caldeadline[document.getElementById("calform_deadline").value-1][al];
    var price_mod = 0.85;
    var work = 1;
    total = Math.round(Math.round(total*price_mod*add*(round_off? 10 : 1))*work)/(round_off? 10 : 1);
  }

  var valid1 = calvalid;
  calvalid = true;
  calvalidate_field("calform_pages");
  document.getElementById("calprice_div").innerHTML="AED 0";

  if (calvalid) {
    if (valid1) {
      totalp = total*document.getElementById("calform_pages").value;
      document.getElementById("calprice_div").innerHTML="AED "+(Math.round(totalp*100)/100);
    }
  }
}

function calcountPrice1() {
  calvalid = true;
  calvalidate_field("calform_academic_level1");
  if (calvalid) {
    var al = document.getElementById("calform_academic_level1").value;
  }
  var add = 1;
  var round_off = false;
  var pages_name = 1;         

  if (pages_name == 1) {
    document.getElementById("pages_name1").innerHTML="Number of pages:";    
  }
  calvalidate_field("calform_deadline1");
  document.getElementById("calprice_div1").innerHTML="AED 0";

  if (calvalid) {
    var total = caldeadline[document.getElementById("calform_deadline1").value-1][al];
    var price_mod = 0.85;
    var work = 1;
    total = Math.round(Math.round(total*price_mod*add*(round_off? 10 : 1))*work)/(round_off? 10 : 1);
  }
  var valid1 = calvalid;
  calvalid = true;
  calvalidate_field("calform_pages1");
  if (calvalid) {
    if(valid1) {
     totalp = total*document.getElementById("calform_pages1").value;
     document.getElementById("calprice_div1").innerHTML="AED "+Math.round(totalp*100)/100;
   }
  }
}