它不起作用(html和javascript和iframe) [英] It doesn't work (html and javascript and Iframe)
问题描述
我使用javascript(动态)将代码添加到iframe的元素中。
在我设置了所有的东西之后。 iframe中的JavaScript不起作用(onclick = functionName(在iframe中定义)...不识别javascript函数)
有什么不对...
这是我的片段。
//初始化
var destiframe = $('#tmpresult')。contents();
destiframe.find('head')。empty();
destiframe.find('body')。empty();
//添加脚本和样式
destiframe.find('head')。append(< style>< / style>);
destiframe.find('body')。append('< script type =text / javascript>< / script>');
//附加定制代码
jQuery.each(代码,函数(i,code){
switch(i){
case 0:
destiframe.find('style')。append(code.value);
break;
case 1:
destiframe.find('body')。append(code。值);
break;
情况2:
destiframe.find('script')。append(code.value);
break;
default:
console.log(empty set);
break;
< a href =https://i.stack.imgur.com/1jpqC.jpg =nofollow noreferrer>
我认为这只是我的错误。
- 如果有人想在iframe中引用javascript函数。 iframe必须参考定义函数的源代码,该函数在组件中引用...
这是我的解决方案。
-
在'view.py'中,定义索引s
def upload_file(request ):
context = {'source_list':source_list,'menu_list':menu_list,'form':fileform,'index':1}
return render(request,'encyclopedia / maintab.html',上下文)
-
在'(template document name).html'中,进行索引。
{%if index == 0%}
목록보기(< - 这是韩国人。英文show list ...)
< / a>
{%elif index == 1%}
목록보기(< - 这是韩国人。英文show list ...)
< / a>
{%endif%}
-
不要忘记像下面那样定义iframe
< form class =form-horizontalmethod =POSTaction =./ upload>
...
< input type =submitid =transferbuttonvalue =vvvvvvvvvvvvvvv/>
< / form>
-
在'Urls.py'中
urlpatterns = [
url(r'^ encylopedia / index $',views.index,name ='index'),
url(r'^上传$',views.upload_file,name ='upload_file'),
url(r'^ $',views.index,name ='index'),
]
很难理解Django框架...
thnks。
但是当点击按钮时它会闪烁一些......
Related.. (HTML, JAVASCRIPT, Iframe)
I add code into Iframe's element using javascript(Dynamically.).
After I set all of things. JavaScript in Iframe doesn't work( onclick=functionName(defined inside iframe)... doesn't identify javascript function)
what's wrong...
this is my snippet.
//initialize
var destiframe = $('#tmpresult').contents();
destiframe.find('head').empty();
destiframe.find('body').empty();
//add script and style
destiframe.find('head').append("<style></style>");
destiframe.find('body').append('<script type="text/javascript"></script>');
//attach customized code
jQuery.each( code, function( i, code ) {
switch(i){
case 0:
destiframe.find('style').append(code.value);
break;
case 1:
destiframe.find('body').append(code.value);
break;
case 2:
destiframe.find('script').append(code.value);
break;
default:
console.log("empty set");
break;
I think it's just my mistake.
-- If someone want to refer javascript function in iframe. iframe must refer source code which define function that component in body refer...
this is my solution..
In 'view.py', define index s
def upload_file(request): context = {'source_list':source_list,'menu_list':menu_list, 'form':fileform, 'index':1} return render(request, 'encyclopedia/maintab.html', context)
In '(template document name).html', define what to do according to index.
{% if index == 0 %} <a id="nav-{{service.menu}}-tab" class="nav-item nav-link active" role="tab" data-toggle="tab" aria-controls="{{service.menu}}-tab" href="#{{service.menu}}-tab"> 목록 보기(<- this is korean. In English "show list...") </a> {% elif index == 1 %} <a id="nav-{{service.menu}}-tab" class="nav-item nav-link" role="tab" data-toggle="tab" aria-controls="{{service.menu}}-tab" href="#{{service.menu}}-tab"> 목록 보기(<- this is korean. In English "show list...") </a> {% endif %}
Don't forgot to define iframe like below
<form class="form-horizontal" method ="POST" action="./upload" > ... <input type="submit" id="transferbutton" value="vvvvvvvvvvvvvvv"/> </form>
In 'Urls.py'
urlpatterns = [ url(r'^encylopedia/index$', views.index, name='index'), url(r'^upload$', views.upload_file, name='upload_file'), url(r'^$', views.index, name='index'), ]
It is difficult to understand Django framework... thnks.
but it makes some blink... when click button.
这篇关于它不起作用(html和javascript和iframe)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!