Мне действительно нравится помещать маленький оператор на ту же строку как если
int myFunc(int x) {
if(x >20) return -1;
//do other stuff ....
}
I do not know a solution using jQuery, but you can find out the DOM node in the current caret position in most browsers quite easily using:
Good luck!
Если я правильно понимаю, вам нужна функция, работающая точно так же, как document.write, я не понимаю, почему вам это нужно, а не просто использовать document.write?
это просто: просто дайте атрибут id вашему встроенному тегу скрипта:
<script id="hello">alert("hello");</script>
, тогда вы можете просто сделать:
$('script#hello').after('<span style="color:red">this is my new content</span>');
ОБНОВЛЕНИЕ:
, поскольку вы не хотите изменять html, то единственной альтернативой является доступ к тегам сценария в соответствии с их порядком появления в коде.
$('script').each(function(index){
// "index" gives you the instance number, which you could use, for example inside a switch case.
switch(index){
case '1':
$(this).after('<span style="color:red">i am number 1</span>');
break;
case '2':
$(this).after('<span style="color:red">i am number 2</span>');
break;
default:
$(this).after('<span style="color:red">i am number '+index+'</span>');
break;
}
});
или вы можете получить доступ к конкретному тегу через .eq (index):
$('script').eq(2).after('hello world');
// this is for the third script tag, starting from the top of the document.