簡體   English   中英

將jQuery包含到javascript中並在imacros中使用它?

[英]include jQuery into javascript and use it in imacros ?

我想知道如何將jQuery庫包含到javascript中並在iMacros中使用它?

它是這樣的。 進入.js文件我將iMacros代碼聲明為變量

var someMacro;
someMacro ="CODE:";
someMacro +="TAB T=1 \n";

代碼實際上更大,這只是一個小例子。 在我聲明變量之后,我使用像iimPlay,iimSet等命令來播放宏並在宏內部設置變量。

現在我如何在其中包含jQuery庫,以便我可以在.js文件中使用jQuery並增強我的腳本?

PS我在他們的論壇上發現了這個,但它對我幫助不大,因為我不明白如何使用它。 這是鏈接到iopus論壇關於jQuery的鏈接

我來這個解決方案:

function loadScriptFromURL(url) {
    var request = Components.classes['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Components.interfaces.nsIXMLHttpRequest),
        async = false;
    request.open('GET', url, async);
    request.send();
    if (request.status !== 200) {
        var message = 'an error occurred while loading script at url: ' + url + ', status: ' + request.status;
        iimDisplay(message);
        return false;
    }
    eval(request.response);
    return true;
}

// load JQuery
loadScriptFromURL('http://mysupersecret.blob.core.windows.net/share/jquery-2.0.3.min.js');
$ = window.$,
JQuery = window.JQuery;

試圖從它的官方CDN獲取jQuery,我遇到了iMacros中的“setTimeout is undefined”錯誤。 所以我下載了jQuery並修改了setTimeout方法為window.setTimeout 這對我有用,所以我不得不將jQuery放在我的在線共享位置以便從那里使用它。 希望這可以幫助。

感謝您將此解決方案整合在一起 我成功加載了jQuery,然后創建了一個bootstrap模式並將其附加到正文。 接下來我嘗試加載bootstrap.js並在模態上調用模態('show')方法,但無濟於事。 iMacros告訴我函數.modal不存在。

loadScriptFromURL('http://localhost.com:7001/ybswcsstub/resources/plugins/jquery-1.10.2.min.js');

$ = window.$, JQuery = window.JQuery;

$.getScript('http://localhost.com:7001/ybswcsstub/resources/plugins/bootstrap/js/bootstrap.js');

$('body').append('<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
'  <div class="modal-dialog">'+
'    <div class="modal-content">'+
'      <div class="modal-header">'+
'        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>'+
'        <h4 class="modal-title" id="myModalLabel">Modal title</h4>'+
'      </div>'+
'      <div class="modal-body">'+
'        Some Modal'+
'      </div>'+
'      <div class="modal-footer">'+
'        <button type="button" class="btn btn-default"     data-dismiss="modal">Close</button>'+
'        <button type="button" class="btn btn-primary">Save changes</button>'+
'      </div>'+
'    </div>'+
'  </div>'+
'</div>');

$('#myModal').modal('show');

當我運行時,我在iMacros TypeError中收到以下錯誤:$(...)。modal不是函數,第211行(錯誤代碼:-991)

任何幫助將不勝感激,因為我有點卡在這一點:s

編輯:我不得不使用$ .getScript來加載bootstrap.js(域中的.com是因為stackoverflowrestriction),因為當我嘗試使用loadScriptFromURL時,我收到了錯誤

Error: Bootstrap's JavaScript requires jQuery, line 7 (Error code: -991)

謝謝,馬克。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM