0

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

谢谢

代码:

<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>
4

3 回答 3

1

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

于 2013-04-25T09:21:54.213 回答
0

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

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

改变这个:

$('#selector')

对此:

document.getElementById('selector')

这同样适用于以下方法:

.val()

.value

所以改变这个:

 $('#selector').val()

对此:

document.getElementById('selector').value;

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

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

于 2013-04-25T09:39:38.553 回答
0

要么在本地下载并使用 jQuery,要么只使用纯 JS

这是我进行一些更改后的脚本演示。它不起作用,因为 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;
   }
  }
}
于 2013-04-25T09:57:33.550 回答