验证PHP代码打印的HTML时出错

时间:2016-04-08 08:29:12

标签: php html html5

该行

print("<tr class='pointer' onclick=location.href='inventory.phpsetID=$setid&catID=$catID'>");
验证代码时,

会触发错误:

Error: "=" in an unquoted attribute value. Probable causes: 
Attributes running together or a URL query string in an unquoted attribute value

Link to validator

我不知道触发它的原因,也不了解错误的解释。

3 个答案:

答案 0 :(得分:1)

您需要使用PHP连接运算符.将字符串与变量连接:

print "<tr class='pointer' onclick=location.href='inventory.php?setID=" . $setid . "&catID=" . $catID "'>"

答案 1 :(得分:1)

你的OnClick需要在引号内,变量应该在引号之外。

print("<tr class='pointer' onclick=\"location.href='inventory.php?setID=" . $setid . "&catID=" . $catID . "'>\"");

答案 2 :(得分:0)

将您的代码更改为:

 private Map<String, String> eventsForThisCategory;
    ...
    Map<String, String> getEventsForThisCategory() {
        if (eventsForThisCategory == null) {
            Collection<INotificationEventsObj> notificationEvents = notificationEventsIndex.getCategoryNotificationEvents(getCategoryId());
            eventsForThisCategory = new HashMap<String, String>();
            for(INotificationEventsObj notificationEvent : notificationEvents) {
                eventsForThisCategory.put(notificationEvent.getNotificationEventID(), notificationEvent.getNotificationEventName());
            }
            logger.debug("eventsForThisCategory is {}", eventsForThisCategory);
        }
        return eventsForThisCategory;
    }

属性 onlick 的值应该在引号内。