سؤال

أنا أعمل على CMS تقوم بإنشاء عبارات CSS "Style = 'xyz'" من إدخال المستخدم. سيتم التحقق من صحة إدخال المستخدم ولكن كحماية إضافية ، أريد التحقق من صحة القيم على توليد رمز CSS.

إذا تمت مواجهة قيمة غير صالحة - على سبيل المثال ، عرض نسبي ("50 ٪") حيث يُسمح فقط للقيم المطلقة بسبب قيود التخطيط - أود إعادة تعليق داخل سمة النمط للمساعدة في تصحيح:

<div class="content" style="background-color: lightblue; /* WIDTH was invalid: Only absolute values allowed here */; border: 1px orange dotted;">

هل هذا "آمن" ، أي هل ستظل جميع المتصفحات الرئيسية تحليل الإعدادات قبل وبعد التعليق بشكل صحيح؟ من الصعب على Google معلومات حول هذا الموضوع.

هل كانت مفيدة؟

المحلول

It is probably safe but I wouldn't put the wrong values commented into the markup.

Let the user know they did something wrong in the very beginning before you generate markup.

A good idea would be to create such a test case and feed it to the W3C validator to see what it would say says about it.

http://validator.w3.org/

نصائح أخرى

From the top of my head, IE supports it, Fx doesn't.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top