简体   繁体   English

Javascript回显HTML而不是对其进行处理

[英]Javascript echoing out HTML rather than processing it

I'm trying to customise the output from a WordPress plugin called Showtime. 我正在尝试自定义名为Showtime的WordPress插件的输出。 Showtime contains the following Javascript to output what is entered in the schedule. Showtime包含以下Javascript,用于输出计划中输入的内容。 For styling reasons I'm entering into the plugin admin area for a show - 出于样式原因,我正在进入插件管理区域进行表演-

<h3>Drivetime</h3><p>with Davie Boy</p>

The issue I have is this is literally printed out / echoed on the page and the html is not rendered / processed, as though wrapped in pre tags. 我的问题是,这实际上是在页面上打印出来/回显的,并且HTML并未呈现/处理,就像包裹在pre标签中一样。

I understand the following javascript outputs the show, how could I get it to actually not echo the html but process it. 我了解以下javascript输出的显示,我如何才能让它实际上不回显html而是对其进行处理。 Sorry if I'm not using the correct terminology. 抱歉,如果我使用的术语不正确。

Any help much appreciated 任何帮助,不胜感激

rob

UPDATE 更新

Thanks for the comments - to get me thinking. 感谢您的评论-让我思考。 This javascript is getting the Showname from a PHP script called crud.php. 此javascript是从名为crud.php的PHP脚本获取Showname的。 Looking over this I think this may be the offending line in crud.php 仔细研究一下,我认为这可能是crud.php中令人讨厌的行

$showname   = htmlentities(stripslashes(($_POST['showname'])));

rather than the javascript itself? 而不是JavaScript本身?

jQuery(function($){

function get_current_show() {
//Get the current show data
$.post(crudScriptURL, {"crud-action" : "read", "read-type" : "current"}, function (currentShowJSON) {

    var schedule = $.parseJSON(currentShowJSON);
    var outputHTML = '';

    var currentShow = schedule['current-show'];
    if (currentShow.showName){
        var currentShowName = currentShow.showName;
        var imageURL = currentShow.imageURL;
        var linkURL = currentShow.linkURL;
        var startClock = currentShow.startClock;
        var endClock = currentShow.endClock;

        outputHTML += '<div id="showtime">'+currentShowName+'</div>';

        if (imageURL){
            if (linkURL){
                outputHTML += '<a href="'+linkURL+'"><img class="showtime-image-thumbnail" src="'+imageURL+'" alt="'+currentShow.showName+'" /></a>';
            } else {
                outputHTML += '<img class="showtime-image-thumbnail" src="'+imageURL+'" alt="'+currentShow.showName+'" />';
            }
        }

    } else {

        outputHTML += '<h3 class="current-show">'+currentShow+'<h3>';

    }

    var upcomingShow = schedule['upcoming-show'];
    if (upcomingShow){
        var upcomingShowName = upcomingShow.showName;
        var upcomingShowLink = upcomingShow.linkURL;
        var upcomingStartClock = upcomingShow.startClock;
        var upcomingEndClock = upcomingShow.endClock;

        if (upcomingShowLink){
            outputHTML += '<h3 class="upcoming-show"><strong>Up next:</strong> <a href="'+upcomingShowLink+'">'+upcomingShowName+'</a></h3>';
        } else {
            outputHTML += '<h3 class="upcoming-show"><strong>Up next:</strong> '+upcomingShowName+'</h3>';
        }

        outputHTML += '<span>'+upcomingStartClock + ' - ' + upcomingEndClock + '</span>';

    }

    $('.showtime-now-playing').html(outputHTML);

    //Set a timer to update the widget every 30 seconds
    setTimeout (get_current_show, (30 * 1000));

});

}

get_current_show();


});

If you have a consistent format for these, and don't really need to use symbols as part of the display, you can implement a sort of parser in the jquery function. 如果这些格式具有一致的格式,并且实际上不需要在显示中使用符号,则可以在jquery函数中实现某种解析器。 For example, you could enter <h3>Drivetime</h3><p>with Davie Boy</p> , and in the code do something like: 例如,您可以<h3>Drivetime</h3><p>with Davie Boy</p>输入<h3>Drivetime</h3><p>with Davie Boy</p> ,然后在代码中执行以下操作:

var currentShowName = $('<div/>').html(currentShow.showName).text();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在JavaScript字符串中使用javascript模板而不是原始HTML? - How to use javascript templating rather than raw HTML in javascript string? 使django的消息显示在Javascript警报而不是html中? - Making django's messages appear in Javascript alert rather than html? 是否有一个JavaScript物理库可以使用div等HTML元素而不是画布? - Is there a JavaScript physics library that works with HTML elements such as divs rather than in canvas? 如何使JavaScript从HTML而不是硬编码数据读取? - How to get JavaScript to read from a HTML rather than hardcoded data? 从 Javascript 文件而不是 HTML/CSS 中检索变量值 - Retrieving variable values from Javascript file rather than HTML/CSS Javascript可以修改HTML流而不是DOM树吗? - Can Javascript modify the HTML stream rather than DOM tree? HTML画布和Javascript-图像周围的阴影而不是边框 - HTML Canvas & Javascript - Shadow Around Image Rather Than Border 使用按钮滚动而不是滚动条css,html,javascript - Scroll using buttons rather than scroll bar css,html,javascript 用嵌套引号将JavaScript脚本从PHP脚本拖到HTML页面上? - Echoing out JavaScript with nested quotes from a PHP script onto an HTML page? 从PHP到javascript回显HTML BODY变量 - Echoing HTML BODY variables from PHP to javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM