كيفية إدخال
نصائح أخرى
إذا كنت ترغب في تضمين JavaScript في الرأس ، فقد تفعل شيئًا كهذا:
$$('head').first().insert({
bottom: new Element('script', {
type: 'text/javascript'
}).update('function helloWorldToConsole(){console.log("Hello World!")}')
});
هذا ينشئ علامة نصية جديدة وإدراجها في أسفل رأسك. ولكن سيكون من أجمل بكثير إذا قمت بإضافة ملف JavaScript خارجي مثل هذا:
$$('head').first().insert({
bottom: new Element('script', {
type: 'text/javascript',
src: 'http://www.example.com/path/file.js'
})
});
يمكنك من استخدام الوظائف لاحقًا في البرامج النصية الخاصة بك.
جرب هذا..
$('<script></script>',{
type:'custom',
id:'script1'
}).appendTo('head').attr('type','text/javascript');
$('#script1').append(< add js code here >);
});
لا تنتمي إلى StackOverflow