Microsoft Word文档的jQuery加载(函数) [英] jQuery load(function) for a Microsoft Word Document

查看:84
本文介绍了Microsoft Word文档的jQuery加载(函数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是针对学校项目的课程,该课程是在线的,现在不再非常准确.我想将.load(function)与.click函数结合使用,所以当我单击相应的单词时,在内容div中获得以下相应的文本,这是到目前为止的代码(我承认不是很好.

This is for a school project the course is online and not very accurate anymore. I want to use the .load(function) combined with a .click function so when I click the corresponding word I get the corresponding text below in the content div this is my code so far (not very good I will admit.

<script type="text/javascript">
$(document).ready(function() {
    var massage=('massage.docx')
    $('.selection').click(function() {
        $('.selection').load(massage.docx)

    });
});
</script>

我要这样做,所以当我单击它时,将其放在其他文本顶部的内容" div中.

I want to make it so when i click it puts it in the "content" div at the top before the other text.

推荐答案

来自jQuery文档: https: //api.jquery.com/load/

说明:从服务器加载数据并放置返回的HTML 放入匹配的元素.

Description: Load data from the server and place the returned HTML into the matched element.

这对您不起作用,因为您使用的是.docx文件类型,该文件类型不会返回html(甚至常规文本).它可能可以完成某事,但是输出可能会出现乱码.服务器上是否有此massage.docx文件?

This isn't going to work for you because you're using a .docx file type which is not going to return html (or even regular text). It might manage to do something but the output is likely to be garbled. Do you have this massage.docx file on the server?

以下内容完全无效:

$('.selection').load(massage.docx)

我认为您的意思是(请注意,您必须在此处使用字符串):

I think what you meant is (note that you must use a string here):

$('.selection').load("massage.docx")

但是,这仍然不起作用,因为您正尝试将Microsoft Word文档加载为HTML,而这只是无法正常工作.您应该将Massage.docx转换为常规文本或html文件-将其上载到您从中调用此javascript的位置的服务器中,然后重试.

But this still won't work because you are trying to load a microsoft word document as HTML, and that just simply won't function properly. You should convert your massage.docx either to regular text, or to an html file - upload it to the server in the same location that you are calling this javascript from, and try this again.

另外,使用浏览器的JavaScript控制台检查JS错误.在chrome中,您可以通过右键单击任意位置,选择检查元素",然后切换到检查器工具上的控制台"标签来执行此操作.

Also, use your browser's javascript console to check for JS errors. In chrome you can do this by right clicking anywhere, selecting "inspect element", and switching to the "Console" tab on the inspector tool.

如果要确保点击操作完全正常,则可能需要添加一些检查:

If you want to make sure the click is even working at all, you might want to add some checks:

$(document).ready(function() {
    var massage=('massage.docx');
    $('.selection').click(function() {
        alert("Clicked!  Attempting to load...");
        $(this).load(massage, function(){
            alert("Loading finished!");
        });
    });
});

这篇关于Microsoft Word文档的jQuery加载(函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆